/**
 * @file 常量
 */

import moment from 'moment';
import {isMobile} from '@/utils/utils';
// 存储钱的时候单位为分
// 获取钱的时候也需要转换
export const BASIC_MONEY = 100;

// 还款日
export const DEFAULT_DAY = 15;

// 格式化日期字符串
export const THE_MOMENT_YYYYMMDD_HHMMSS = 'YYYY/MM/DD HH:mm:ss';
export const THE_MOMENT_YYMMDD_HHMMSS = 'YYYY/MM/DD HH:mm:ss';
export const THE_MOMENT_YYMMDD_HHMM = 'YYYY/MM/DD HH:mm';
export const THE_MOMENT_YYMMDD = 'YYYY/MM/DD';
// eslint-disable-next-line max-len
export const THE_EL_DATE_PICK_FORMAT = 'yyyy/MM/dd HH:mm:ss'; // 注意：这个时 element-ui 特殊的 https://element.eleme.cn/#/zh-CN/component/date-picker

// 收款方式、付款方式
export function getRevenueOptionsMode() {
    return [
        {value: '1', label: '微信'},
        {value: '2', label: '支付宝'},
        {value: '3', label: '银行卡'},
        {value: '4', label: '现金'},
        {value: '5', label: '信用卡'},
        {value: '-1', label: '其他'}
    ];
}

export function getRevenueModeMap() {
    const revenueModeMap = {};
    const modes = getRevenueOptionsMode();
    modes.forEach(item => {
        revenueModeMap[item.value] = item.label;
    });
    return revenueModeMap;
}

// 收、付款状态
export function getRevenueOptionsStatus() {
    return [
        {value: '1', label: '已完成'},
        {value: '2', label: '延期到账'},
        {value: '3', label: '已退款'},
        {value: '4', label: '退款中'},
        {value: '-2', label: '已取消'}
    ];
}

export function getRevenueStatusMap() {
    const revenueStatusMap = {};
    getRevenueOptionsStatus().forEach(item => {
        revenueStatusMap[item.value] = item.label;
    });
    return revenueStatusMap;
}

/**
 * 获取默认日期配置
 */
export function getPickerOptions() {
    if (isMobile) {
        return {};
    }
    return {
        shortcuts: [
            {
                text: '今天',
                onClick(picker) {
                    const start = moment(new Date()).format('YYYY-MM-DD 00:00:00');
                    const end = moment(new Date()).format('YYYY-MM-DD 23:59:59');
                    picker.$emit('pick', [start, end]);
                }
            },
            {
                text: '最近一周',
                onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                    picker.$emit('pick', [start, end]);
                }
            },
            {
                text: '最近一个月',
                onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                    picker.$emit('pick', [start, end]);
                }
            },
            {
                text: '最近三个月',
                onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                    picker.$emit('pick', [start, end]);
                }
            }
        ]
    };
}
